﻿<div class="container-fluid">
    <div class="row-fluid">
        <div class="span12">
            <div class="widget-box">
                <div class="widget-title">
                    <span class="icon"><i class="icon-th"></i></span>
                    <h5>栏目列表</h5>
                </div>
                <div class="widget-content">
                    <table class="table table-bordered table-striped">
                        <thead>
                            <tr>
                                <th>栏目名称
                                </th>
                                <th>操作
                                </th>
                            </tr>
                        </thead>
                        <tbody>
                            @{
                                var pid = 0;
                                foreach (Meun item in ViewBag.PagList)
                                {
                                <tr>
                                    <td>
                                        @if (item.ParentId == 0)
                                        {
                                            pid = item.ID;
                                            <i class="icon-list"></i>
                                        }
                                        else if (item.ParentId == pid)
                                        {
                                            <span>&nbsp;&nbsp;∟</span>
                                        }
                                        else
                                        {
                                            <span>&nbsp;&nbsp;&nbsp;&nbsp;∟</span>
                                        }
                                        @item.Name
                                    </td>
                                    <td style="text-align: center">
                                        <input type="button" value="发布" class="btn btn-primary" onclick="publish(@item.ID)" />
                                    </td>
                                </tr>
                                }
                            }
                        </tbody>
                    </table>
                </div>
            </div>
        </div>
    </div>
</div>
<div id="myAlert" class="modal hide in" aria-hidden="false">
    <div class="modal-header">
        <button id="btnClose" data-dismiss="modal" class="close" type="button">×</button>
        <h3>发布中</h3>
    </div>
    <div id="divProcess" class="modal-body">
        <p>发布页面需要一些时间，请耐心等待...</p>
        <div class="progress progress-striped active">
            <div class="bar" style="width: 100%;">
            </div>
        </div>
    </div>
    <div id="divOk" class="modal-body hide">
        <p>
            页面已经发布完成，请点击下载发布包.
        </p>
        <div class="progress progress-striped progress-success">
            <div class="bar" style="width: 100%;">
            </div>
        </div>
    </div>
    <div id="divError" class="modal-body hide">
        <p>
            没有需要发布的页面或发布过程中出错，请稍后重试.
        </p>
        <div class="progress progress-striped progress-danger">
            <div class="bar" style="width: 100%;">
            </div>
        </div>
    </div>
    <div class="modal-footer hide">
        <a data-dismiss="modal" id="btnDownload" class="btn btn-success" href="#">下载</a>
    </div>
</div>
<div id="divShadow" class="modal-backdrop hide in "></div>
<script type="text/javascript">
    var ispublishing = false;
    //发布指定栏目
    function publish(id) {
        $("#myAlert").show();
        $("#divShadow").show();
        ispublishing = true;
        $.post('@Url.Action("ByMenu", "Publish")', { "id": id }, function(result) {
            ispublishing = false;
            $("#divProcess").hide();
            if (result !== "Error" && result !== "No") {
                $("#divOk").show();
                $("#myAlert .modal-footer").show();
                $("#btnDownload").attr("href", result);
            } else {
                $("#divError").show();
            }
        });
    }
    
    $(function() {
        $("#divShadow").click(function() {
            if (!ispublishing) {
                $("#myAlert").hide();
                $("#divProcess").show();
                $("#divOk").hide();
                $("#divError").hide();
                $("#myAlert .modal-footer").hide();
                $(this).hide();
            }
        });

        $("#btnClose").click(function() {
            $("#myAlert").hide();
            $("#divProcess").show();
            $("#divOk").hide();
            $("#divError").hide();
            $("#myAlert .modal-footer").hide();
            $("#divShadow").hide();
        });
    });
</script>
